//////////////////////////////////////////////////////////////////////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	File			:	"MainMenuState.cpp"
//	Authors			:	Jake Castillo,
//	Project			:	Project Aetheryte
//	Date Modified	:	8/7/2013
//	Purpose			:	MainMenuState is the state for the main menu of our game. The player 
//						will choose from various different options here. 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////////////////

#include "MainMenuState.h"
#include "OptionsState.h"

/*static*/ MainMenuState* MainMenuState::GetInstance( void )
{
	static MainMenuState Menu_Instance;
	return &Menu_Instance;
}

MainMenuState::MainMenuState(void)
{
	CursorPosition	= 0;
	TitleFont		= nullptr;
	MenuFont		= nullptr;

	FontChangeTimer = 0.0f;
	count			= 1;
}


MainMenuState::~MainMenuState(void)
{
}

/*virtual*/ void MainMenuState::Enter ( void )	
{
	TitleFont = CGame::GetInstance()->GetTitleFont();
	MenuFont  = CGame::GetInstance()->GetMenuFont();

	FontChangeTimer = 0.0f;
	count			= 1;

	bool isLoaded =	false;	//LoadXMLOptions();

	if(isLoaded == false)
	{
		CGame::GetInstance()->SetBGVolume(0.5f);
		CGame::GetInstance()->SetSFXVolume(0.5f);
		CGame::GetInstance()->SetLanguage(CGame::GetInstance()->English);
	}
}

/*virtual*/ void MainMenuState::Exit  ( void )	
{

}

/*virtual*/ bool MainMenuState::Input ( void )	
{
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();

	// Press Escape to quit the application
	if( /*ControllerInput::DidCancel(controls)*/ pDI->KeyPressed(DIK_ESCAPE) )
	{
		CursorPosition = 3;
		PlayMove();
	}

	if( /*ControllerInput::Up(controls)*/ pDI->KeyPressed(DIK_UP) || pDI->KeyPressed(DIK_W) )
	{
		CursorPosition--;

		if( CursorPosition < 0 )		// 0 for New Game
			CursorPosition = 3;

		//PlayMove();
	}
	else if( /*ControllerInput::Down(controls)*/ pDI->KeyPressed(DIK_DOWN) || pDI->KeyPressed(DIK_S) )
	{
		CursorPosition++;

		if( CursorPosition > 3 )		// 3 to Exit
			CursorPosition = 0;

		//PlayMove();
	}

	if( pDI->KeyPressed(DIK_RETURN) )
	{
		switch(CursorPosition)
		{
		case 0:
			break;

		case 1:
			break;

		case 2:
			CGame::GetInstance()->ChangeState(OptionsState::GetInstance());
			break;

		case 3:
			return false;
			break;
		}
	}

	return true;
}

/*virtual*/ void MainMenuState::Update( float fElapsedTime )	
{
	FontChangeTimer += fElapsedTime;

	if(FontChangeTimer >= 10.0f)
	{
		FontChangeTimer = 0.0f;
		count++;

		if(count > 3)
			count = 1;
	}
}

/*virtual*/ void MainMenuState::Render( void )			
{
	if(count == 1)
	{
		// Menu Test 1 - Title Font
		TitleFont->Draw(_T("Project Aetheryte"), 10, 10, 2.0f,   D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 0)
			TitleFont->Draw(_T("New Game"),		10, 400, 1.25f,  D3DCOLOR_XRGB(255, 255, 255));
		else													 
			TitleFont->Draw(_T("New Game"),		10, 400, 1.0f,   D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 1)									 
			TitleFont->Draw(_T("Load Game"),	10, 475, 1.25f,  D3DCOLOR_XRGB(255, 255, 255));
		else													 
			TitleFont->Draw(_T("Load Game"),	10, 475, 1.0f,   D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 2)									 
			TitleFont->Draw(_T("Options"),		10, 550, 1.25f,  D3DCOLOR_XRGB(255, 255, 255));
		else													 
			TitleFont->Draw(_T("Options"),		10, 550, 1.0f,   D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 3)									 
			TitleFont->Draw(_T("Exit"),			10, 625, 1.25f,  D3DCOLOR_XRGB(255, 255, 255));
		else													 
			TitleFont->Draw(_T("Exit"),			10, 625, 1.0f,   D3DCOLOR_XRGB(255, 255, 255));
	}
	else if(count ==2)
	{
		// Menu Test 2 - Title Font && Menu Font
		TitleFont->Draw(_T("Project Aetheryte"), 10, 10, 2.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 0)
			MenuFont->Draw(_T("New Game"),		10, 400, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("New Game"),		10, 400, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 1)					
			MenuFont->Draw(_T("Load Game"),		10, 475, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Load Game"),		10, 475, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 2)					
			MenuFont->Draw(_T("Options"),		10, 550, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Options"),		10, 550, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 3)					
			MenuFont->Draw(_T("Exit"),			10, 625, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Exit"),			10, 625, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));
	}
	else if(count == 3)
	{
		// Menu Test 3 - Menu Font
		MenuFont->Draw(_T("Project Aetheryte"), 10, 10, 2.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 0)
			MenuFont->Draw(_T("New Game"),		10, 400, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("New Game"),		10, 400, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 1)					
			MenuFont->Draw(_T("Load Game"),		10, 475, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Load Game"),		10, 475, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 2)					
			MenuFont->Draw(_T("Options"),		10, 550, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Options"),		10, 550, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));

		if(CursorPosition == 3)					
			MenuFont->Draw(_T("Exit"),			10, 625, 1.25f, D3DCOLOR_XRGB(255, 255, 255));
		else									
			MenuFont->Draw(_T("Exit"),			10, 625, 1.0f,  D3DCOLOR_XRGB(255, 255, 255));
	}
}
